import React,{useRef,useEffect} from 'react';
import * as echarts from 'echarts';
import {get} from "../../../service";
function PieChart(props) {
    const ref =useRef()
    useEffect(()=>{
       const echart= echarts.init(ref.current)
        const options = {
           tooltip:{
               show:true
           },
           series:[
               {
                  type:'pie',//饼图
                  radius:'50%',//半径
                  label:{
                      formatter:'{b}:{d}%'//b:数据名，d：是数据值
                  },
                   data:[
                       {name:'图书',value:100},
                       {name:'数码',value:200},
                   ]
               }
           ]
        }
        echart.setOption(options)
        window.addEventListener('resize',()=>{
            echart.resize()
        })
        get('/api/overview/producttypesales').then(res=>{
            echart.setOption({
                series:[{data:res.records}]
            })
        })
    },[])
    return (
        <div ref={ref} style={{height:'100%'}}></div>
    );
}

export default PieChart;